package com.zzw.ratelimter;

/**
 * @author Administrator
 */
public interface RateLimiter {

    Response isAllowed(String id);

    class Response {
        private final boolean allowed;
        private final long tokensRemaining;

        public boolean isAllowed() {
            return allowed;
        }

        public long getTokensRemaining() {
            return tokensRemaining;
        }

        public Response(boolean allowed) {
            this.allowed = allowed;
            this.tokensRemaining = -1L;
        }

        public Response(boolean allowed, long tokensRemaining) {
            this.allowed = allowed;
            this.tokensRemaining = tokensRemaining;
        }


        @Override
        public String toString() {
            return "Response{" + "allowed=" + this.allowed +
                    ", tokensRemaining=" + this.tokensRemaining +
                    '}';
        }
    }
}
